﻿using CPPEI.Coolzon.Event.Core;
using CPPEI.Coolzon.Event.NCL;
using CPPEI.Coolzon.Event.UI;
using CPPEI.Coolzon.Theme.Events;
using CPPEI.Coolzon.UI;
using CPPEI.Coolzon.UI.Event;
using CPPEI.Coolzon.UI.Views;
using CPPEI.Coolzon.UI.Views.Events;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CPPEI.Coolzon.Theme.Fashion.MainViewControl
{
    /// <summary>
    /// SystemFunction.xaml 的交互逻辑
    /// </summary>
    public partial class SystemFunction : UserControl
    {
        /// <summary>
        /// 场景名称
        /// </summary>
        private string sceneName;

        public SystemFunction()
        {
            InitializeComponent();

            //判断是否是全屏
            if (UIContext.Current.IsFullScreen)
            {
                FullScreen.Content = "还原";
            }
            else
            {
                FullScreen.Content = "全屏";
            }
        }

        /// <summary>
        /// 退出
        /// </summary>
        private void btn_Quit(object sender, RoutedEventArgs e)
        {
            CPPEI.Coolzon.Theme.Fashion.Views.ExitView exitView = new Views.ExitView();
            exitView.Close += exitView_Close;
            UIContext.Current.RootViewContainer.PopView("退出", exitView);
        }

        void exitView_Close(View view, bool isCancel)
        {
            if (!isCancel)
            {
                Application.Current.Shutdown();
            }
        }

        /// <summary>
        /// 注销
        /// </summary>
        private void btn_Logout(object sender, RoutedEventArgs e)
        {
            LogoutView logoutView = new LogoutView();
            UIContext.Current.RootViewContainer.PopView("注销", logoutView);
        }

        /// <summary>
        /// 全屏
        /// </summary>
        private void btn_FullScreen(object sender, RoutedEventArgs e)
        {
            UIEventBus.Publish(new UIChangeFullScreenStateEvent());
            if (UIContext.Current.IsFullScreen)
            {
                FullScreen.Content = "还原";
            }
            else
            {
                FullScreen.Content = "全屏";
            }
        }

        /// <summary>
        /// 重置方案
        /// </summary>
        private void btn_ResetSolution(object sender, RoutedEventArgs e)
        {
            Common.EventBus.Instance.Publish(new BeginResetSolutionEvent(UIContext.Current.SolutionName));
        }

        /// <summary>
        /// 切换方案
        /// </summary>
        private void btn_SelectSolution(object sender, RoutedEventArgs e)
        {
            Common.EventBus.Instance.Publish(new UIShowSwitchSolutionViewEvent());
        }

        /// <summary>
        /// 自动播放
        /// </summary>
        private void btn_AutoPlay(object sender, RoutedEventArgs e)
        {
            if (UIContext.Current.Solution.Displayflow != null && UIContext.Current.Solution.Displayflow.Nodes.Count > 0)
            {
                this.Dispatcher.Invoke(
                    () =>
                    {
                        CPPEI.Coolzon.UI.Views.AutoPlayView autoPlayView = new CPPEI.Coolzon.UI.Views.AutoPlayView();
                        UIEventBus.Register(autoPlayView);
                        NCLEventBus.Register(autoPlayView);
                        CoreEventBus.Register(autoPlayView);
                        UIContext.Current.RootViewContainer.PopView("自动播放", autoPlayView, false);
                    });
            }
        }

        private void btnExtentionFunction_Click_1(object sender, RoutedEventArgs e)
        {
            ExtentionFunctionPanel panel = new ExtentionFunctionPanel();
            panel.ShowDialog();
        }

        /// <summary>
        /// 点击删除缓存
        /// </summary>
        private void OnBtnDeleteDataCacheClick(object sender, RoutedEventArgs e)
        {
            CPPEI.Coolzon.Event.Core.CoreEventBus.Publish(new Coolzon.Event.Core.CoreDeleteDataCacheFileEvent());
        }

    }
}
